﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblCPerson_CommMemberBLL
    {
        private  ItblCPerson_CommMember IDAL;
        public tblCPerson_CommMemberBLL()
        {
            IDAL = DataAccess.CreateItblCPerson_CommMember();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblCPerson_CommMemberBLL GetInstance()
        {
            return new tblCPerson_CommMemberBLL();
        }

        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(tblCPerson_CommMember ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(tblCPerson_CommMember ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(tblCPerson_CommMember ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception er)
                {

                    throw er;
                }
            }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<tblCPerson_CommMember> GetListByENT(tblCPerson_CommMember ent,PageParam param, string strPropertyName,string strOrderBy)
        {
            List<tblCPerson_CommMember> list=new List<tblCPerson_CommMember>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblCPerson_CommMember> GetListByENT(tblCPerson_CommMember ent)
        {
            List<tblCPerson_CommMember> list = new List<tblCPerson_CommMember>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        /// <summary>
        /// 根据tblCust_ContactPerson 查询 tblCPerson_CommMember结果集
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="isToCP">是否相对于CP,True:只查询CP的Commitee记录； False:查询Customer的Commitee记录</param>
        /// <returns></returns>
        public List<tblCPerson_CommMember> GetListByCust_CPerson(tblCust_ContactPerson ent,bool isToCP)
        {
            List<tblCPerson_CommMember> list = new List<tblCPerson_CommMember>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByCust_CPerson(ent, isToCP);
                }
                catch (Exception er)
                {
                    throw er;
                }
            }
            return list;
        }

        public tblCPerson_CommMember GetEntity(tblCPerson_CommMember ent)
        {
            tblCPerson_CommMember ret=new tblCPerson_CommMember();
            if (ent != null)
            {
                ret = IDAL.GetListByENT(ent).FirstOrDefault();
            }
            return ret;
        }

        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(tblCPerson_CommMember ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }

        public List<CommitteeMemberList> GetListByCPUID(int CPUID,List<int> withOutList)
        {
            List<CommitteeMemberList> list = new List<CommitteeMemberList>();
            if (CPUID > 0)
            {
                try { list = IDAL.GetListByCPUID(CPUID, withOutList); }
                catch (Exception er) { throw; }
            }
            return list;
        }

        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(tblCPerson_CommMember ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
